﻿/* Copyright (c) 2011 Mahir Iqbal
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.bayvakoof.dewall.geom
{
	import flash.geom.Point;
	
	/**
	 * Data structure for triangles
	 * @author Mahir Iqbal
	 */
	public class Triangle 
	{
		//public var vertices:Vector.<Point>;		
		//private var faceList:Vector.<Face>;
		public var v1:Point;
		public var v2:Point;
		public var v3:Point;
		
		public var face1:Face;
		public var face2:Face;
		public var face3:Face;
		
		public function Triangle(v1:Point, v2:Point, v3:Point, face1:Face, face2:Face, face3:Face)
		{
			//vertices = new Vector.<Point>(3);
			//vertices[0] = v1;
			//vertices[1] = v2;
			//vertices[2] = v3;
			this.v1 = v1;
			this.v2 = v2;
			this.v3 = v3;
			this.face1 = face1;
			this.face2 = face2;
			this.face3 = face3;
		}
		
		/*public function get faces():Vector.<Face>
		{
			if (faceList)
				return faceList;
			
			faceList = new Vector.<Face>();
			
			var temp:Face;
			
			temp = new Face(vertices[0], vertices[1]);
			temp.triPoint = vertices[2];
			faceList.push(temp);
			
			temp = new Face(vertices[1], vertices[2]);
			temp.triPoint = vertices[0];
			faceList.push(temp);
			
			temp = new Face(vertices[0], vertices[2]);
			temp.triPoint = vertices[1];
			faceList.push(temp);
			
			return faceList;
		}*/
		
		public function getOppositedFace(p: Point): Face
		{
			if(v1 == p)
				return face1;
			else if(v2 == p)
				return face2;
			else if(v3 == p)
				return face3;
			return null;
		}
		
		public function getOppositedVertex(face:Face):Point
		{
			if(face1 == face)
				return v1;
			if(face2 == face)
				return v2;
			if(face3 == face)
				return v3;
			return null;
		}
		
		public function getAdjacentFaces(p:Point): Array
		{
			if(v1 == p)
				return [face2, face3];
			else if(v2 == p)
				return [face3, face1];
			else if(v3 == p)
				return [face1, face2];
			return null;
		}
	}
	
}